package MineGod;

import java.io.IOException;
import java.util.Random;

import org.lwjgl.opengl.GL11;
import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureLoader;
import org.newdawn.slick.util.ResourceLoader;

public class BlockStone extends Block {
	
	public static Texture stoneTex;
	public static Texture mossStoneTex;
	private Texture tex;
	
	public BlockStone(){
		super(BlockType.stone);
		durability = 200;
		int a = Chunk.rand.nextInt(10);
		if (a < 2){
			tex = mossStoneTex;
		} else
			tex = stoneTex;
	}
	
	public void render(double x, double y)
	{
		GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
		getTexture().bind();
		GL11.glColor3d(1, (durability)/maxDurability/2+.5, (durability)/maxDurability/2+.5); // Could make this faster!!
		GL11.glBegin(GL11.GL_QUADS);
			GL11.glNormal3d(0, 0, 1);
			GL11.glTexCoord2d(0.0, 0.0);
			GL11.glVertex3d(x, y, zIndex);
			GL11.glTexCoord2d(1.0, 0.0);
			GL11.glVertex3d(x + WIDTH, y, zIndex);
			GL11.glTexCoord2d(1.0, 1.0);
			GL11.glVertex3d(x + WIDTH, y + WIDTH, zIndex);
			GL11.glTexCoord2d(0.0, 1.0);
			GL11.glVertex3d(x, y + WIDTH, zIndex);
		GL11.glEnd();
	}

	@Override
	public Entity dropItem(double x, double y) {
		if (tex == stoneTex){
			return null;
		}
		else{
			Random rand = new Random();
			if (rand.nextInt(100)<20){
				return new ItemEntityDiamond(x,y);
			}
			else{
				return null;
			}
		}
	}

	@Override
	public Texture getTexture() {
		return tex;
	}

	public static void loadTexture() {
		try {
			stoneTex = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/mcStone.png"));
			mossStoneTex = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/mossStone.png"));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
